package com.vegetable.modules.vo;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

/**
 * <p>
 * 价格要素详细信息VO
 * </p>
 *
 * @author Qwen
 * @since 2025-09-27
 */
@Data
@ApiModel(value="价格要素详细信息VO", description="价格要素详细信息VO")
public class PriceElementDetailVO {

    @ApiModelProperty(value = "库存ID")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long stockId;

    @ApiModelProperty(value = "日期")
    private Date orderTime;

    @ApiModelProperty(value = "商品ID")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long commodityId;

    @ApiModelProperty(value = "商品名称")
    private String commodityName;

    @ApiModelProperty(value = "规格ID")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long specsId;

    @ApiModelProperty(value = "规格名称")
    private String specsName;

    @ApiModelProperty(value = "商品类型")
    private String category;

    @ApiModelProperty(value = "包装单价（按重均摊）")
    private BigDecimal packageUnitPrice;

    @ApiModelProperty(value = "蔬菜单价")
    private BigDecimal goodsUnitPrice;

    @ApiModelProperty(value = "每公斤成本价格")
    private BigDecimal costWeight;

    @ApiModelProperty(value = "入库类型")
    private Integer storageType;

    @ApiModelProperty(value = "入库类型描述")
    private String storageTypeDescription;

    @ApiModelProperty(value = "仓库名称")
    private String warehouseName;

    @ApiModelProperty(value = "批次编号")
    private String stockBatchNo;

    @ApiModelProperty(value = "包装成本组成")
    private String packageCost;

    @ApiModelProperty(value = "库存对应的入库单明细")
    private Long stockDetailId;

    @Excel(name = "标重")
    private BigDecimal standard;

    private BigDecimal initWeight;

    private BigDecimal initNumber;
    
    /**
     * 获取实际包装单价（小包装商品为0）
     * @return 包装单价
     */
    public BigDecimal getActualPackageUnitPrice() {
        if ("小包装".equals(this.category)) {
            return BigDecimal.ZERO;
        }
        return this.packageUnitPrice;
    }
    
    /**
     * 获取实际每公斤成本价格（小包装商品为每公斤成本价格 + 包装单价）
     * @return 每公斤成本价格
     */
    public BigDecimal getActualCostWeight() {
        if ("小包装".equals(this.category)) {
            BigDecimal costWeightValue = this.costWeight != null ? this.costWeight : BigDecimal.ZERO;
            BigDecimal packageUnitPriceValue = this.packageUnitPrice != null ? this.packageUnitPrice : BigDecimal.ZERO;
            return costWeightValue.add(packageUnitPriceValue);
        }
        return this.costWeight;
    }
}